package org.lem

import grails.test.*
import jxl.Workbook

class ImportServiceServiceTests extends GrailsUnitTestCase {

  FileInputStream fis

  protected void setUp() {
    super.setUp()

    File dbDump = new File("C:/workspace_lem/LEM.xls")
    fis = new FileInputStream(dbDump)
  }

  protected void tearDown() {
    super.tearDown()
  }

  void testImportXlsFile() {
    //ImportService importService = new ImportService()
    //importService.importXlsFile fis

  }

  void testLoadStudents() {
    //Workbook workbook = Workbook.getWorkbook(fis);
    //ImportService importService = new ImportService()
    //importService.loadStudents(workbook);
    //workbook.close();
  }


  void testStudentRowCount() {
    Workbook workbook = Workbook.getWorkbook(fis);
    def sheet = workbook.getSheet("LEM_STUDENTS");
    assertEquals(2946, sheet.getRows())
    workbook.close()
  }

  void testLoadCountries() {
    Workbook workbook = Workbook.getWorkbook(fis);
    ImportService importService = new ImportService()
    importService.loadCountries(workbook);
    workbook.close();
  }

  void testCountryRowCount() {
    Workbook workbook = Workbook.getWorkbook(fis);
    def sheet = workbook.getSheet("COUNTRIES");
    assertEquals(257, sheet.getRows())
    workbook.close()
  }

  void testLocationRowCount() {
    Workbook workbook = Workbook.getWorkbook(fis);
    def sheet = workbook.getSheet("LOCATIONS");
    assertEquals(10, sheet.getRows())
    workbook.close()
  }

  void testLocationLoad() {
    Workbook workbook = Workbook.getWorkbook(fis);
    ImportService importService = new ImportService()
    importService.loadLocations(workbook);
    workbook.close();
  }

  void testStudentLearninSkillLoad() {
    Workbook workbook = Workbook.getWorkbook(fis);
    ImportService importService = new ImportService()
    importService.loadStudentLearningSkills(workbook);
    workbook.close();
  }

}
